package com.byd.android.MusicPlayer;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;

public class MusicImageTask extends AsyncTask<byte[], Integer, Bitmap> {
    private byte[] params;
    private ImageView musicImageIv;

    public MusicImageTask(byte[] params, ImageView musicImageIv) {
        this.params = params;
        this.musicImageIv = musicImageIv;
    }


    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected Bitmap doInBackground(byte[]... bytes) {
        bytes[0] = params;
        if(bytes[0] != null) {
            Bitmap bitmap = BitmapFactory.decodeByteArray(bytes[0], 0, bytes[0].length);
            Bitmap newmap = Bitmap.createScaledBitmap(bitmap, 1000, 1000, true);
        //    Drawable drawable  = new BitmapDrawable(,newBmp);
            return newmap;
        }else{return null;}

    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
    }

    @Override
    protected void onPostExecute(Bitmap bitmap) {
        super.onPostExecute(bitmap);
        try {
            Log.d(this.getClass().getSimpleName(), "onPostExecute: musicImageIv.setImageBitmap");
            musicImageIv.setImageBitmap(bitmap);
            musicImageIv.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
